package com.mu.securitysso.dao;

import com.mu.securitysso.entity.Role;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Select;

import java.util.List;

/**
 * @author sht
 */
@Mapper
public interface RoleDao {


    @Select(value=" SELECT sr.* FROM s_role sr " +
            " LEFT JOIN s_user_role sur ON sr.id = sur.fk_role_id " +
            " LEFT JOIN s_user su ON sur.fk_user_id = su.id " +
            " WHERE su.id = #{UserId} ")
    List<Role> findRoleListByUserId(int userId);

    /**
     * 根据资源路径获取角色列表
     * @param PermissionUrl
     * @return
     */
    @Select(value=" SELECT sr.* FROM s_role sr " +
            " LEFT JOIN s_role_permission srp ON sr.id = srp.fk_role_id " +
            " LEFT JOIN s_permission sp ON srp.fk_permission_id = sp.id " +
            " WHERE sp.url = #{PermissionUrl} ")
    List<Role> findRoleListByPermissionUrl(String PermissionUrl);

}
